package Model;

/**
 * Created by xuxingcan on 2016/7/20.
 */
public class CardModel implements Comparable<CardModel> {
    public static final int TYPE_NONE = 0, TYPE_BING = 1, TYPE_TIAO = 2, TYPE_WAN = 3;
    public static final int NUMBER_NONE = 0;
    private int number = NUMBER_NONE;
    private int type = TYPE_NONE;

    public int getType() {
        return type;
    }

    public int getNumber() {
        return number;
    }

    public CardModel(int type, int number) {
        this.number = number;
        this.type = type;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof CardModel) {
            CardModel cardModel = (CardModel) obj;
            return cardModel.getNumber() == number && cardModel.getType() == type;
        } else {
            return super.equals(obj);
        }
    }

    public boolean smallerThanTheGiven(CardModel model) {
        if (model.getType() == type && model.getNumber() == number + 1) {
            return true;
        } else {
            return false;
        }
    }

    public boolean biggerThanTheGiven(CardModel model) {
        if (model.getType() == type && model.getNumber() == number - 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int compareTo(CardModel o) {
        if (getType() == o.getType()) {
            return getNumber() - o.getNumber();
        } else {
            return getType() - o.getType();
        }
    }

    @Override
    public String toString() {
        String s = "";
        switch (getNumber()) {
            case 1:
                s += "一";
                break;
            case 2:
                s += "二";
                break;
            case 3:
                s += "三";
                break;
            case 4:
                s += "四";
                break;
            case 5:
                s += "五";
                break;
            case 6:
                s += "六";
                break;
            case 7:
                s += "七";
                break;
            case 8:
                s += "八";
                break;
            case 9:
                s += "九";
                break;
        }
        switch (getType()) {
            case TYPE_BING:
                s += "筒";
                break;
            case TYPE_TIAO:
                s += "条";
                break;
            case TYPE_WAN:
                s += "万";
                break;
        }
        return s;
    }
}
